package adminorg;

import com.vaadin.terminal.ExternalResource;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.DragAndDropWrapper;
import com.vaadin.ui.Label;
import com.vaadin.ui.Link;
import com.vaadin.ui.Panel;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.Runo;


public class OrgItem extends Panel {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -8516759384266545741L;
	private Object ItemID;
	private int Id;
	private int PId;
	private String Code;
	private Label Name;
	private Label DeptName;
	private Label AccName;
	private boolean Manager;
	private Link Docs;
	private int Level;
	private VerticalLayout L = new VerticalLayout();
	private VerticalLayout LP = new VerticalLayout();
	private DragAndDropWrapper LW = null;
	
	public OrgItem(){
		
	}
	
	public OrgItem(Object ItemID,int Id, int PId, String Code, String Name, String DeptName,boolean Manager, String Docs, int Level, String LevelName, String AccName){
		this();
		this.ItemID = ItemID;
		this.Id=Id;
		this.PId=PId;
		this.Code= Code;
		this.Name= new Label(Name);
		this.DeptName=new Label(DeptName);
		if (Docs!=null)	this.Docs = new Link(Docs, new ExternalResource(Docs));
			else this.Docs=null; 
		this.Level = Level;
		this.setCaption(this.Code);
		L.addComponent(this.Name);
		L.addComponent(this.DeptName);
		if (this.Docs!=null) {
			L.addComponent(this.Docs);
			this.Docs.setStyleName(Runo.TEXTFIELD_SMALL);
		}
		if (Manager){this.Name.setStyleName(Runo.LABEL_H1);}
		this.Manager = Manager;
		L.setComponentAlignment(this.Name, Alignment.TOP_CENTER);
		L.setComponentAlignment(this.DeptName,Alignment.TOP_CENTER);
		if (AccName!=null)
			this.AccName = new Label(AccName);
		else this.AccName = new Label("");
		L.addComponent(this.AccName);
		LW =  new DragAndDropWrapper(L);
		LW.setSizeFull();
		L.setSizeFull();
		LP.addComponent(LW);
		this.setContent(LP);
	}
	
	public VerticalLayout getL(){
		return L;
	}
	
	public DragAndDropWrapper getLW(){
		return LW;
	} 
	
	public int getId(){
		return this.Id;
	}
	public int getLevel(){
		return this.Level;
	}
	
	public int getPid(){
		return this.PId;
	}
	
	public Label getName(){
		return this.Name;
	}
	public Label getDeptName(){
		return this.DeptName;
	}
	
	public boolean getManager(){
		return this.Manager;
	}
	
	public Object getItemID(){
		return this.ItemID;
	}
	
	public Label getAccName(){
		return this.AccName;
	}
	
	public void setAccName(String AccName){
		L.removeComponent(this.AccName);
		if (AccName!=null)
			this.AccName = new Label(AccName);
		else this.AccName = new Label("");
		L.addComponent(this.AccName);
	}
}
